Skip to content

fix(autogen-core): pass positional-only tool arguments positionally - #8415

Open
Phani Paladugula (phanipaladugula) wants to merge 1 commit into
microsoft:mainfrom
phanipaladugula:fix-function-tool-positional-only
Open

Phani Paladugula (phanipaladugula) wants to merge 1 commit into
microsoft:mainfrom
phanipaladugula:fix-function-tool-positional-only

Conversation

@phanipaladugula

Copy link
Copy Markdown

Why are these changes needed?

FunctionTool builds a valid argument schema for an annotated function with positional-only parameters, but run() passed every argument by keyword. Validation therefore succeeded and the call then failed with TypeError:

TypeError: scale() got some positional-only arguments passed as keyword arguments: 'value'

This affects sync and async functions, and an injected cancellation_token declared as positional-only.

run() now collects positional-only parameters and passes them positionally, in signature order, keeping all other parameters as keywords. Sync functions still link the future only when the wrapped function does not take the cancellation token, as before.

Related issue number

Closes #8319

Checks

  • I've added tests corresponding to the changes introduced in this PR.
  • I've made sure the relevant auto checks have passed.

Verification

Tests added to python/packages/autogen-core/tests/test_tools.py:

  • sync and async functions with positional-only parameters and a keyword-only default;
  • a positional-only parameter whose default is used when it is omitted;
  • a positional-only injected cancellation_token;
  • a mix of positional-only and keyword parameters.

Each case fails on the unchanged implementation for the reported reason and passes with the change.

$ uv run --with pytest-asyncio --with pytest-mock --package autogen-core \
    pytest packages/autogen-core/tests -q \
    --ignore=packages/autogen-core/tests/test_json_to_pydantic.py \
    --ignore=packages/autogen-core/tests/test_model_context.py
147 passed

$ uv run --with ruff==0.4.8 ruff check <changed files>
All checks passed!

(The two ignored files need autogen-ext, which is not part of this package's test environment.)

FunctionTool generated a valid schema for annotated functions with
positional-only parameters, but run() always called the wrapped function
with keyword arguments, so every call raised TypeError after validation.

Collect positional-only parameters and pass them positionally in
signature order, keeping the rest as keywords. This also covers an
injected cancellation_token declared as positional-only, and preserves
the existing cancellation behaviour for sync functions.

Closes microsoft#8319
@phanipaladugula

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@phanipaladugula

Copy link
Copy Markdown
Author

Hi Eric Zhu (@ekzhu) — this is ready for review whenever you have a moment. It fixes #8319 by splitting positional-only arguments out before building kwargs, with five regression tests. pytest packages/autogen-core/tests → 147 passed; CLA and GitGuardian are green.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FunctionTool raises TypeError for positional-only parameters after successful schema validation

1 participant